var fn = require('../../../util/util.js');
var mUrl = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var movieId=options.id;
    this.setData({
      movieId: movieId
    });
    console.log(this.data);
    // var id = this.data.MovieId;
    var url = mUrl.globalData.m_url + '/v2/movie/subject/' + movieId;
    console.log(url);
    var that=this;
    wx.request({
      url: url,
      method: 'GET',
      header: {
        'content-type': 'json'
      },
      success: function (res) {
        console.log(res.data);
        // 在处理从服务端获取的数据时，单层属性获取不用判空，多层属性必须判空
        var movie={
          img: res.data.images ? res.data.images.large:'',
          title: res.data.original_title,
          country: res.data.countries[0],
          year: res.data.year,
          commentCount: res.data.comments_count,
          wishCount: res.data.wish_count,
          stars: fn.getStarArr(res.data.rating.stars),
          score: res.data.rating.average,
          directors: fn.convertToString(res.data.directors),
          castsStr: fn.convertToString(res.data.casts),
          castsArr: fn.convertToArr(res.data.casts),
          genres: res.data.genres.join(' 、'),
          summary: res.data.summary
        }
        that.setData({
          movieInfo: movie
        });
      }
    });
    console.log(this.data);
  },
  getMovieDetailInfo: function () {

  },
  // 图片预览效果
  onPreviewImg: function (even) {
    console.log(0);
    var src = even.currentTarget.dataset.src;
    console.log(src);
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: [src, src] // 需要预览的图片http链接列表
    });
  }

})